


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html id="htmlId">
<head>
  <title>Coverage Report :: Main</title>
  <style type="text/css">
    @import "../../.css/coverage.css";
  </style>
</head>

<body>
<div class="header"></div>

<div class="content">
<div class="breadCrumbs">
    [ <a href="../../index.html">all classes</a> ]
    [ <a href="../index.html">edu.ncsu.csc326.coffeemaker</a> ]
</div>

<h1>Coverage Summary for Class: Main (edu.ncsu.csc326.coffeemaker)</h1>

<table class="coverageStats">
<tr>
  <th class="name">Class</th>
<th class="coverageStat 
">
  Class, %
</th>
<th class="coverageStat 
">
  Method, %
</th>
<th class="coverageStat 
">
  Line, %
</th>
</tr>
<tr>
  <td class="name">Main</td>
<td class="coverageStat">
  <span class="percent">
    0%
  </span>
  <span class="absValue">
    (0/ 1)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    0%
  </span>
  <span class="absValue">
    (0/ 11)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    0%
  </span>
  <span class="absValue">
    (0/ 154)
  </span>
</td>
</tr>

</table>

<br/>
<br/>


<div class="sourceCode"><i>1</i>&nbsp;package edu.ncsu.csc326.coffeemaker;
<i>2</i>&nbsp;
<i>3</i>&nbsp;import java.io.BufferedReader;
<i>4</i>&nbsp;import java.io.IOException;
<i>5</i>&nbsp;import java.io.InputStreamReader;
<i>6</i>&nbsp;
<i>7</i>&nbsp;/**
<i>8</i>&nbsp; * 
<i>9</i>&nbsp; * @author Sarah E. Smith
<i>10</i>&nbsp; *
<i>11</i>&nbsp; * Starts the console UI for the CoffeeMaker
<i>12</i>&nbsp; */
<b class="nc"><i>13</i>&nbsp;public class Main {</b>
<i>14</i>&nbsp;    private static CoffeeMaker coffeeMaker;
<i>15</i>&nbsp;
<i>16</i>&nbsp;    public static void mainMenu() {
<b class="nc"><i>17</i>&nbsp;        System.out.println(&quot;1. Add a recipe&quot;);</b>
<b class="nc"><i>18</i>&nbsp;        System.out.println(&quot;2. Delete a recipe&quot;);</b>
<b class="nc"><i>19</i>&nbsp;        System.out.println(&quot;3. Edit a recipe&quot;);</b>
<b class="nc"><i>20</i>&nbsp;        System.out.println(&quot;4. Add inventory&quot;);</b>
<b class="nc"><i>21</i>&nbsp;        System.out.println(&quot;5. Check inventory&quot;);</b>
<b class="nc"><i>22</i>&nbsp;        System.out.println(&quot;6. Make coffee&quot;);</b>
<b class="nc"><i>23</i>&nbsp;        System.out.println(&quot;0. Exit\n&quot;);</b>
<i>24</i>&nbsp;        
<i>25</i>&nbsp;        //Get user input
<b class="nc"><i>26</i>&nbsp;        int userInput = stringToInt(inputOutput(&quot;Please press the number that corresponds to what you would like the coffee maker to do.&quot;));</b>
<i>27</i>&nbsp;        
<b class="nc"><i>28</i>&nbsp;        if(userInput == 1) addRecipe();</b>
<b class="nc"><i>29</i>&nbsp;        if(userInput == 2) deleteRecipe();</b>
<b class="nc"><i>30</i>&nbsp;        if(userInput == 3) editRecipe();</b>
<b class="nc"><i>31</i>&nbsp;        if(userInput == 4) addInventory();</b>
<b class="nc"><i>32</i>&nbsp;        if(userInput == 5) checkInventory();</b>
<b class="nc"><i>33</i>&nbsp;        if(userInput == 6) makeCoffee();</b>
<b class="nc"><i>34</i>&nbsp;        if(userInput == 0) System.exit(0);</b>
<i>35</i>&nbsp;    }
<i>36</i>&nbsp;	public static void addRecipe() {
<i>37</i>&nbsp;	    //Read in recipe name
<b class="nc"><i>38</i>&nbsp;	    String name = inputOutput(&quot;\nPlease enter the recipe name: &quot;);</b>
<i>39</i>&nbsp;	    
<i>40</i>&nbsp;	    //Read in recipe price
<b class="nc"><i>41</i>&nbsp;	    String priceString = inputOutput(&quot;\nPlease enter the recipe price: $&quot;);</b>
<b class="nc"><i>42</i>&nbsp;	    int price = stringToInt(priceString);</b>
<b class="nc"><i>43</i>&nbsp;	    if(price &lt; 0) {</b>
<b class="nc"><i>44</i>&nbsp;	    	mainMenu();</b>
<i>45</i>&nbsp;	    }
<i>46</i>&nbsp;	    
<i>47</i>&nbsp;	    //Read in amt coffee
<b class="nc"><i>48</i>&nbsp;	    String coffeeString = inputOutput(&quot;\nPlease enter the units of coffee in the recipe: &quot;);</b>
<b class="nc"><i>49</i>&nbsp;	    int amtCoffee = stringToInt(coffeeString);</b>
<b class="nc"><i>50</i>&nbsp;	    if(amtCoffee &lt; 0) {</b>
<b class="nc"><i>51</i>&nbsp;	    	mainMenu();</b>
<i>52</i>&nbsp;	    }
<i>53</i>&nbsp;	    
<i>54</i>&nbsp;	    //Read in amt milk
<b class="nc"><i>55</i>&nbsp;	    String milkString = inputOutput(&quot;\nPlease enter the units of milk in the recipe: &quot;);</b>
<b class="nc"><i>56</i>&nbsp;	    int amtMilk = stringToInt(milkString);</b>
<b class="nc"><i>57</i>&nbsp;	    if(amtMilk &lt; 0) {</b>
<b class="nc"><i>58</i>&nbsp;	    	mainMenu();</b>
<i>59</i>&nbsp;	    }
<i>60</i>&nbsp;	    
<i>61</i>&nbsp;	    //Read in amt sugar
<b class="nc"><i>62</i>&nbsp;	    String sugarString = inputOutput(&quot;\nPlease enter the units of sugar in the recipe: &quot;);</b>
<b class="nc"><i>63</i>&nbsp;	    int amtSugar = stringToInt(sugarString);</b>
<b class="nc"><i>64</i>&nbsp;	    if(amtSugar &lt; 0) {</b>
<b class="nc"><i>65</i>&nbsp;	    	mainMenu();</b>
<i>66</i>&nbsp;	    }
<i>67</i>&nbsp;	    
<i>68</i>&nbsp;	    //Read in amt chocolate
<b class="nc"><i>69</i>&nbsp;	    String chocolateString = inputOutput(&quot;\nPlease enter the units of chocolate in the recipe: &quot;);</b>
<b class="nc"><i>70</i>&nbsp;	    int amtChocolate = stringToInt(chocolateString);</b>
<b class="nc"><i>71</i>&nbsp;	    if(amtChocolate &lt; 0) {</b>
<b class="nc"><i>72</i>&nbsp;	    	mainMenu();</b>
<i>73</i>&nbsp;	    }
<i>74</i>&nbsp;	    
<b class="nc"><i>75</i>&nbsp;	    boolean recipeAdded = false;</b>
<b class="nc"><i>76</i>&nbsp;		Recipe r = new Recipe();</b>
<b class="nc"><i>77</i>&nbsp;		r.setName(name);</b>
<b class="nc"><i>78</i>&nbsp;		r.setPrice(price);</b>
<b class="nc"><i>79</i>&nbsp;		r.setAmtCoffee(amtCoffee);</b>
<b class="nc"><i>80</i>&nbsp;		r.setAmtMilk(amtMilk);</b>
<b class="nc"><i>81</i>&nbsp;		r.setAmtSugar(amtSugar);</b>
<b class="nc"><i>82</i>&nbsp;		r.setAmtChocolate(amtChocolate);</b>
<i>83</i>&nbsp;		   
<b class="nc"><i>84</i>&nbsp;		recipeAdded = coffeeMaker.addRecipe(r);</b>
<i>85</i>&nbsp;	    
<b class="nc"><i>86</i>&nbsp;	    if(recipeAdded) System.out.println(name + &quot; successfully added.&quot;);</b>
<b class="nc"><i>87</i>&nbsp;	    else System.out.println(name + &quot;could not be added.&quot;);</b>
<i>88</i>&nbsp;	    
<b class="nc"><i>89</i>&nbsp;	    mainMenu();</b>
<i>90</i>&nbsp;    }
<i>91</i>&nbsp;    
<i>92</i>&nbsp;    public static void deleteRecipe() {
<b class="nc"><i>93</i>&nbsp;        Recipe [] recipes = coffeeMaker.getRecipes();</b>
<b class="nc"><i>94</i>&nbsp;        for(int i = 0; i &lt; recipes.length; i++) {</b>
<b class="nc"><i>95</i>&nbsp;            System.out.println((i+1) + &quot;. &quot; + recipes[i].getName());</b>
<i>96</i>&nbsp;        }
<b class="nc"><i>97</i>&nbsp;        String recipeToDeleteString = inputOutput(&quot;Please select the number of the recipe to delete.&quot;);</b>
<b class="nc"><i>98</i>&nbsp;        int recipeToDelete = stringToInt(recipeToDeleteString) - 1;</b>
<b class="nc"><i>99</i>&nbsp;	    if(recipeToDelete &lt; 0) {</b>
<b class="nc"><i>100</i>&nbsp;	    	mainMenu();</b>
<i>101</i>&nbsp;	    }
<i>102</i>&nbsp;        
<b class="nc"><i>103</i>&nbsp;        boolean recipeDeleted = coffeeMaker.deleteRecipe(recipes[recipeToDelete]);</b>
<i>104</i>&nbsp;        
<b class="nc"><i>105</i>&nbsp;        if(recipeDeleted) System.out.println(recipes[recipeToDelete].getName() + &quot; successfully deleted.&quot;);</b>
<b class="nc"><i>106</i>&nbsp;	    else System.out.println(recipes[recipeToDelete].getName() + &quot;could not be deleted.&quot;);</b>
<i>107</i>&nbsp;        
<b class="nc"><i>108</i>&nbsp;        mainMenu();</b>
<i>109</i>&nbsp;    }
<i>110</i>&nbsp;    
<i>111</i>&nbsp;    public static void editRecipe() {
<b class="nc"><i>112</i>&nbsp;        Recipe [] recipes = coffeeMaker.getRecipes();</b>
<b class="nc"><i>113</i>&nbsp;        for(int i = 0; i &lt; recipes.length; i++) {</b>
<b class="nc"><i>114</i>&nbsp;            System.out.println((i+1) + &quot;. &quot; + recipes[i].getName());</b>
<i>115</i>&nbsp;        }
<b class="nc"><i>116</i>&nbsp;        String recipeToEditString = inputOutput(&quot;Please select the number of the recipe to edit.&quot;);</b>
<b class="nc"><i>117</i>&nbsp;        int recipeToEdit = stringToInt(recipeToEditString) -1;</b>
<b class="nc"><i>118</i>&nbsp;	    if(recipeToEdit &lt; 0) {</b>
<b class="nc"><i>119</i>&nbsp;	    	mainMenu();</b>
<i>120</i>&nbsp;	    }
<i>121</i>&nbsp;        
<b class="nc"><i>122</i>&nbsp;        Recipe oldRecipe = recipes[recipeToEdit];</b>
<i>123</i>&nbsp;        
<i>124</i>&nbsp;	    //Read in recipe name
<b class="nc"><i>125</i>&nbsp;	    String name = inputOutput(&quot;\nPlease enter the recipe name: &quot;);</b>
<i>126</i>&nbsp;	    
<i>127</i>&nbsp;	    //Read in recipe price
<b class="nc"><i>128</i>&nbsp;	    String priceString = inputOutput(&quot;\nPlease enter the recipe price: $&quot;);</b>
<b class="nc"><i>129</i>&nbsp;	    int price = stringToInt(priceString);</b>
<b class="nc"><i>130</i>&nbsp;	    if(price &lt; 0) {</b>
<b class="nc"><i>131</i>&nbsp;	    	mainMenu();</b>
<i>132</i>&nbsp;	    }
<i>133</i>&nbsp;	    
<i>134</i>&nbsp;	    //Read in amt coffee
<b class="nc"><i>135</i>&nbsp;	    String coffeeString = inputOutput(&quot;\nPlease enter the units of coffee in the recipe: &quot;);</b>
<b class="nc"><i>136</i>&nbsp;	    int amtCoffee = stringToInt(coffeeString);</b>
<b class="nc"><i>137</i>&nbsp;	    if(amtCoffee &lt; 0) {</b>
<b class="nc"><i>138</i>&nbsp;	    	mainMenu();</b>
<i>139</i>&nbsp;	    }
<i>140</i>&nbsp;	    
<i>141</i>&nbsp;	    //Read in amt milk
<b class="nc"><i>142</i>&nbsp;	    String milkString = inputOutput(&quot;\nPlease enter the units of milk in the recipe: &quot;);</b>
<b class="nc"><i>143</i>&nbsp;	    int amtMilk = stringToInt(milkString);</b>
<b class="nc"><i>144</i>&nbsp;	    if(amtMilk &lt; 0) {</b>
<b class="nc"><i>145</i>&nbsp;	    	mainMenu();</b>
<i>146</i>&nbsp;	    }
<i>147</i>&nbsp;	    
<i>148</i>&nbsp;	    //Read in amt sugar
<b class="nc"><i>149</i>&nbsp;	    String sugarString = inputOutput(&quot;\nPlease enter the units of sugar in the recipe: &quot;);</b>
<b class="nc"><i>150</i>&nbsp;	    int amtSugar = stringToInt(sugarString);</b>
<b class="nc"><i>151</i>&nbsp;	    if(amtSugar &lt; 0) {</b>
<b class="nc"><i>152</i>&nbsp;	    	mainMenu();</b>
<i>153</i>&nbsp;	    }
<i>154</i>&nbsp;	    
<i>155</i>&nbsp;	    //Read in amt chocolate
<b class="nc"><i>156</i>&nbsp;	    String chocolateString = inputOutput(&quot;\nPlease enter the units of chocolate in the recipe: &quot;);</b>
<b class="nc"><i>157</i>&nbsp;	    int amtChocolate = stringToInt(chocolateString);</b>
<b class="nc"><i>158</i>&nbsp;	    if(amtChocolate &lt; 0) {</b>
<b class="nc"><i>159</i>&nbsp;	    	mainMenu();</b>
<i>160</i>&nbsp;	    }
<i>161</i>&nbsp;	    
<b class="nc"><i>162</i>&nbsp;	    Recipe newRecipe = new Recipe();</b>
<b class="nc"><i>163</i>&nbsp;	    newRecipe.setName(name);</b>
<b class="nc"><i>164</i>&nbsp;	    newRecipe.setPrice(price);</b>
<b class="nc"><i>165</i>&nbsp;	    newRecipe.setAmtCoffee(amtCoffee);</b>
<b class="nc"><i>166</i>&nbsp;	    newRecipe.setAmtMilk(amtMilk);</b>
<b class="nc"><i>167</i>&nbsp;	    newRecipe.setAmtSugar(amtSugar);</b>
<b class="nc"><i>168</i>&nbsp;	    newRecipe.setAmtChocolate(amtChocolate);</b>
<i>169</i>&nbsp;        
<b class="nc"><i>170</i>&nbsp;        boolean recipeEdited = coffeeMaker.editRecipe(oldRecipe, newRecipe);</b>
<i>171</i>&nbsp;        
<b class="nc"><i>172</i>&nbsp;        if(recipeEdited) System.out.println(oldRecipe.getName() + &quot; successfully edited.&quot;);</b>
<b class="nc"><i>173</i>&nbsp;	    else System.out.println(oldRecipe.getName() + &quot;could not be edited.&quot;);</b>
<i>174</i>&nbsp;        
<b class="nc"><i>175</i>&nbsp;        mainMenu();</b>
<i>176</i>&nbsp;    }
<i>177</i>&nbsp;    
<i>178</i>&nbsp;    public static void addInventory() {
<i>179</i>&nbsp;	    //Read in amt coffee
<b class="nc"><i>180</i>&nbsp;	    String coffeeString = inputOutput(&quot;\nPlease enter the units of coffee to add: &quot;);</b>
<b class="nc"><i>181</i>&nbsp;	    int amtCoffee = stringToInt(coffeeString);</b>
<b class="nc"><i>182</i>&nbsp;	    if(amtCoffee &lt; 0) {</b>
<b class="nc"><i>183</i>&nbsp;	    	mainMenu();</b>
<i>184</i>&nbsp;	    }
<i>185</i>&nbsp;	    
<i>186</i>&nbsp;	    //Read in amt milk
<b class="nc"><i>187</i>&nbsp;	    String milkString = inputOutput(&quot;\nPlease enter the units of milk to add: &quot;);</b>
<b class="nc"><i>188</i>&nbsp;	    int amtMilk = stringToInt(milkString);</b>
<b class="nc"><i>189</i>&nbsp;	    if(amtMilk &lt; 0) {</b>
<b class="nc"><i>190</i>&nbsp;	    	mainMenu();</b>
<i>191</i>&nbsp;	    }
<i>192</i>&nbsp;	    
<i>193</i>&nbsp;	    //Read in amt sugar
<b class="nc"><i>194</i>&nbsp;	    String sugarString = inputOutput(&quot;\nPlease enter the units of sugar to add: &quot;);</b>
<b class="nc"><i>195</i>&nbsp;	    int amtSugar = stringToInt(sugarString);</b>
<b class="nc"><i>196</i>&nbsp;	    if(amtSugar &lt; 0) {</b>
<b class="nc"><i>197</i>&nbsp;	    	mainMenu();</b>
<i>198</i>&nbsp;	    }
<i>199</i>&nbsp;	    
<i>200</i>&nbsp;	    //Read in amt chocolate
<b class="nc"><i>201</i>&nbsp;	    String chocolateString = inputOutput(&quot;\nPlease enter the units of chocolate to add: &quot;);</b>
<b class="nc"><i>202</i>&nbsp;	    int amtChocolate = stringToInt(chocolateString);</b>
<b class="nc"><i>203</i>&nbsp;	    if(amtChocolate &lt; 0) {</b>
<b class="nc"><i>204</i>&nbsp;	    	mainMenu();</b>
<i>205</i>&nbsp;	    }
<i>206</i>&nbsp;	    
<b class="nc"><i>207</i>&nbsp;        coffeeMaker.addInventory(amtCoffee, amtMilk, amtSugar, amtChocolate);</b>
<b class="nc"><i>208</i>&nbsp;        mainMenu();</b>
<i>209</i>&nbsp;    }
<i>210</i>&nbsp;    
<i>211</i>&nbsp;    public static void checkInventory() {
<b class="nc"><i>212</i>&nbsp;        Inventory inventory = coffeeMaker.checkInventory();</b>
<b class="nc"><i>213</i>&nbsp;        System.out.println(inventory.toString());</b>
<b class="nc"><i>214</i>&nbsp;        mainMenu();</b>
<i>215</i>&nbsp;    }
<i>216</i>&nbsp;    
<i>217</i>&nbsp;    public static void makeCoffee() {
<b class="nc"><i>218</i>&nbsp;        Recipe [] recipes = coffeeMaker.getRecipes();</b>
<b class="nc"><i>219</i>&nbsp;        for(int i = 0; i &lt; recipes.length; i++) {</b>
<b class="nc"><i>220</i>&nbsp;            System.out.println((i+1) + &quot;. &quot; + recipes[i].getName());</b>
<i>221</i>&nbsp;        }
<b class="nc"><i>222</i>&nbsp;        String recipeToPurchaseString = inputOutput(&quot;Please select the number of the recipe to purchase.&quot;);</b>
<b class="nc"><i>223</i>&nbsp;        int recipeToPurchase = stringToInt(recipeToPurchaseString) -1;</b>
<b class="nc"><i>224</i>&nbsp;	    if(recipeToPurchase &lt; 0) {</b>
<b class="nc"><i>225</i>&nbsp;	    	mainMenu();</b>
<i>226</i>&nbsp;	    }
<i>227</i>&nbsp;        
<b class="nc"><i>228</i>&nbsp;        String amountPaid = inputOutput(&quot;Please enter the amount you wish to pay&quot;);</b>
<b class="nc"><i>229</i>&nbsp;        int amountToPay = stringToInt(amountPaid);</b>
<b class="nc"><i>230</i>&nbsp;	    if(amountToPay &lt; 0) {</b>
<b class="nc"><i>231</i>&nbsp;	    	mainMenu();</b>
<i>232</i>&nbsp;	    }
<i>233</i>&nbsp;        
<b class="nc"><i>234</i>&nbsp;        Recipe recipe = recipes[recipeToPurchase];</b>
<b class="nc"><i>235</i>&nbsp;        int change = coffeeMaker.makeCoffee(recipe, amountToPay);</b>
<i>236</i>&nbsp;        
<b class="nc"><i>237</i>&nbsp;        System.out.println(&quot;Your change is: &quot; + change + &quot;\n&quot;);</b>
<b class="nc"><i>238</i>&nbsp;        mainMenu();</b>
<i>239</i>&nbsp;    }
<i>240</i>&nbsp;    
<i>241</i>&nbsp;    public static String inputOutput(String message) {
<b class="nc"><i>242</i>&nbsp;        System.out.println(message);</b>
<b class="nc"><i>243</i>&nbsp;	    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));</b>
<b class="nc"><i>244</i>&nbsp;	    String returnString = &quot;&quot;;</b>
<i>245</i>&nbsp;	    try {
<b class="nc"><i>246</i>&nbsp;	        returnString = br.readLine();</b>
<i>247</i>&nbsp;	    }
<b class="nc"><i>248</i>&nbsp;	    catch (IOException e){</b>
<b class="nc"><i>249</i>&nbsp;	        System.out.println(&quot;Error reading in value&quot;);</b>
<b class="nc"><i>250</i>&nbsp;	        mainMenu();</b>
<b class="nc"><i>251</i>&nbsp;	    }</b>
<b class="nc"><i>252</i>&nbsp;	    return returnString;</b>
<i>253</i>&nbsp;    }
<i>254</i>&nbsp;    
<i>255</i>&nbsp;    private static int stringToInt(String value) {
<b class="nc"><i>256</i>&nbsp;        int returnInt = -1;</b>
<i>257</i>&nbsp;        try {
<b class="nc"><i>258</i>&nbsp;            returnInt = Integer.parseInt(value);</b>
<i>259</i>&nbsp;        }
<b class="nc"><i>260</i>&nbsp;        catch (NumberFormatException e) {</b>
<b class="nc"><i>261</i>&nbsp;            System.out.println(&quot;Please input an integer\n&quot;);</b>
<b class="nc"><i>262</i>&nbsp;        }</b>
<b class="nc"><i>263</i>&nbsp;        return returnInt;</b>
<i>264</i>&nbsp;    }
<i>265</i>&nbsp;    
<i>266</i>&nbsp;    public static void main(String[] args) {
<b class="nc"><i>267</i>&nbsp;	    coffeeMaker = new CoffeeMaker();</b>
<b class="nc"><i>268</i>&nbsp;	    System.out.println(&quot;Welcome to the CoffeeMaker!\n&quot;);</b>
<b class="nc"><i>269</i>&nbsp;	    mainMenu();</b>
<i>270</i>&nbsp;	}
<i>271</i>&nbsp;}
</div>
</div>

<div class="footer">
    
    <div style="float:right;">generated on 2014-04-26 20:19</div>
</div>
</body>
</html>
